/*
 * 		Author : Xerxes
 * 		Program: 
 * 		Created On : 30.09.2011 21:32:18 BDT
 *      "I have not failed, I have just found 10000 ways that won't work.
 * 
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int G[101][101];
int N;
int K=1;

inline void Read(){
	CI(N);
		fo(i,0,N){
			fo(j,0,N){
				scanf("%d",&G[i][j]);
			}
		}
}

int P[101][101];
int cango[ 101 ];

inline void doit( ){
	SET(cango,0);
	stack< int > q;
	q.push( 0 );
	cango[0]=1;
	
	while( q.empty()==false ){
		int father = q.top();
		q.pop();
		
		for(int i=0;i<N;++i){
			if( cango[i]==0 && G[father][i]==1 ){
				cango[i]=1;
				q.push(i);
			}
		}
	}
	
}
inline void doit2(int bad){
	SET(cango,0);
	stack<int> q;
	
	q.push( 0 );
	cango[0]=1;
	
	while( q.empty()==false ){
		int father = q.top();
		q.pop();
		
		for(int i=0;i<N;++i){
			if( bad!=i && cango[i]==0 && G[father][i]==1 ){
				cango[i]=1;
				q.push(i);
			}
		}
	}
	
	
}

inline void Proc(){
	SET(P,0);
	
	// handle 0 specially
	doit();
	fo(i,0,N){
		if( cango[i]!=0 ){
			P[0][i]=1;
		}
	}
	
	// now check other nodes
	fo(i,1,N){
		doit2(i);
			fo(j,1,N){
				if( cango[j]==0 && P[0][j]==1){
					P[i][j]=1;
				}
			}
	}
	string feed(N+N+1,'-');
	feed[0]=feed[N+N]='+';
	printf("Case %d:\n",K);
	fo(i,0,N){
		printf("%s\n",feed.c_str());
		fo(j,0,N){
			printf("|%c",P[i][j]==1 ? 'Y' : 'N' );
			if(j+1==N){
				printf("|\n");
			}
		}
	}
	printf("%s\n",feed.c_str());
	
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    int cases=1;
    for( CI(cases) ; cases ; --cases,++K ){
        Read();
        Proc();
    }

return 0;
}



